package com.ceadeal.admin.web;

import com.ceadeal.admin.service.FileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件上传
 *
 * @author Westin Yang
 * @date 2017-03-13 20:54:23
 */
@Controller
@RequestMapping("/file")
public class FileController {

    private static final Logger log = LoggerFactory.getLogger(FileController.class);

    @Autowired
    private FileService fileService;

    /**
     * 功能描述：文件上传
     * @return
     * @throws
     *
     * @author Yzw
     * @date 2016/8/17 0017,9:03
     **/
    @ResponseBody
    @RequestMapping(value = {"/upload"}, method = {RequestMethod.POST})
    public String upload(HttpServletRequest request, HttpServletResponse response, MultipartFile file) throws InterruptedException {
        response.setContentType("text/html; charset=UTF-8");
        //String siteUrl = String.format("http://%s:%d", request.getServerName(), request.getServerPort());
        return this.fileService.upload(request, file);
    }

}
